package vn.com.fsoft.business.impl;

import java.util.List;
import java.util.Set;

import vn.com.fsoft.business.IGovOfficeRegionBusiness;
import vn.com.fsoft.model.dao.impl.GovOfficeRegionDAO;
import vn.com.fsoft.model.entities.County;
import vn.com.fsoft.model.entities.GovOfficeRegion;

public class GovOfficeRegionBusiness implements IGovOfficeRegionBusiness {
	private GovOfficeRegionDAO govOfficeRegionDAO;
	private static int totalPage;
	
	public GovOfficeRegionBusiness() {
		super();
		this.govOfficeRegionDAO = new GovOfficeRegionDAO();
	}

	public GovOfficeRegionDAO getGovOfficeRegionDAO() {
		return govOfficeRegionDAO;
	}

	public void setGovOfficeRegionDAO(GovOfficeRegionDAO govOfficeRegionDAO) {
		this.govOfficeRegionDAO = govOfficeRegionDAO;
	}

	@Override
	public List<GovOfficeRegion> getAllGovOffice(int page, int recordPerPage) {
		GovOfficeRegionBusiness.setTotalPage(govOfficeRegionDAO.getTotalPage());
		if (page == 0) {
			page = 1;
		}
	/*	if(page>maxPage){
			page = maxPage;
		}*/
		// TODO Auto-generated method stub
		List<GovOfficeRegion> allGov = govOfficeRegionDAO.getAllGovOffice(page,
				recordPerPage);
		for (int i = 0; i < allGov.size(); i++) {
			Set<County> counties = allGov.get(i).getCounties();
			allGov.get(i).setCounties(counties);

		}

		return allGov;
	}

	public static int getTotalPage() {
		return totalPage;
	}

	public static void setTotalPage(int totalPage) {
		GovOfficeRegionBusiness.totalPage = totalPage;
	}
	
}
